package com.shop.admin.service.user;

import com.shop.admin.dao.user.UserBillDao;
import com.shop.domain.user.UserBill;
import com.shop.web.response.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;

@Service
@Slf4j
@Transactional
public class UserBillService {

    @Autowired
    private UserBillDao userBillDao;


    /**
     * 添加用户余额流水记录
     * @param userId  用户ID
     * @param price  金额
     * @param relationId 关联ID
     * @param tableName  关联表
     * @param initialPrice 原始金额
     * @param refreshPrice 更新后金额
     * @param pm 支出类型
     * @param type 支出类型
     * @param title 標題
     * @param mark 备注
     * @return
     */
    public BaseResponse addUserBill(Long userId, BigDecimal price, Long relationId, String tableName, BigDecimal initialPrice,
                                    BigDecimal refreshPrice, int pm, int type, String title, String mark) {

        UserBill userBill = new UserBill();
        userBill.setCreateTime(new Date());
        userBill.setUid(userId);
        userBill.setPrice(price);
        userBill.setRelationId(relationId);
        userBill.setTableName(tableName);
        userBill.setInitialPrice(initialPrice);
        userBill.setRefreshPrice(refreshPrice);
        userBill.setPm(pm);
        userBill.setType(type);
        userBill.setTitle(title);
        userBill.setMark(mark);
        userBillDao.save(userBill);

        return new BaseResponse();
    }





}
